home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / SETFDATE.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  3KB  |  128 lines

  1. /*  SETFDATE.C
  2.  *  last mod.: 28-AUG-91
  3.  */
  4.  
  5. #include <STDIO.H>
  6. #include <STDLIB.H>
  7. #include <STRING.H>
  8.  
  9. #include <L_FILE.H>
  10. #include <L_DIR.H>
  11. #include <L_DATE.H>
  12. #include <L_TIME.H>
  13.  
  14. Uchar *usage = "Use: SETFDATE file_spec [month-day-year] [hour:minute]\n";
  15. Uchar normal_file_spec[_MAX_PATH_];
  16. Uchar date_str[16], time_str[16];
  17.  
  18. /*----------------------------*/
  19. void main(int argc, char **argv)
  20. {
  21. int i, result;
  22. Date date;
  23. Date_format df;
  24. Time time;
  25. Time_format tf;
  26. Str_ptr token;
  27.  
  28. if ( argc < 2 )
  29.     {
  30.     printf(usage);
  31.     exit(0);
  32.     }
  33.  
  34. result = normalize_path(argv[1],normal_file_spec);
  35. if ( result < 0 )
  36.     {
  37.     printf("\nInvalid file specification.\n");
  38.     exit(1);
  39.     }
  40. else if ( result & _PATH_EXISTS_ & _PATH_TO_DIRECTORY_ )
  41.     {
  42.     printf("\nPath leads to subdirectory.\n");
  43.     exit(2);
  44.     }
  45. else if ( ! ( result & _PATH_EXISTS_ ) )
  46.     {
  47.     printf("\nNo files found.\n");
  48.     exit(3);
  49.     }
  50.  
  51. get_system_date(&date);
  52. set_date_format_default(&df);
  53. df.justify = TRUE;
  54. df.date_separator = '-';
  55. date_to_str(&date,&df,date_str);
  56. printf("\nSystem date: %s",date_str);
  57.  
  58. get_system_time(&time);
  59. set_time_format_default(&tf);
  60. tf.hr_justified = TRUE;
  61. tf.style = 1;       /*  24-hour  */
  62. tf.components = 1;  /*  hr:min:sec  */
  63. time_to_str(&time,&tf,time_str);
  64. printf("\nSystem time: %s",time_str);
  65.  
  66. for ( i=2; i<argc; i++ )
  67.     {
  68.     if ( strchr(argv[i],'-') != NULL )
  69.         {
  70.         if ( ( token = strtok(argv[i],"-") ) != NULL )
  71.             {
  72.             date.month = atoi(token);
  73.             if ( ( token = strtok(NULL,"-") ) != NULL )
  74.                 {
  75.                 date.day = atoi(token);
  76.                 if ( ( token = strtok(NULL,"-") ) != NULL )
  77.                     {
  78.                     date.year = atoi(token);
  79.                     if ( date.year < 1900 )
  80.                         date.year += 1900;
  81.                     }
  82.                 }
  83.             }
  84.         }
  85.     else if ( strchr(argv[i],':') != NULL )
  86.         {
  87.         if ( ( token = strtok(argv[i],":") ) != NULL )
  88.             {
  89.             time.hour = (Uchar)atoi(token);
  90.             if ( ( token = strtok(NULL,":") ) != NULL )
  91.                 time.minute = (Uchar)atoi(token);
  92.             time.second = time.hsecond = 0;
  93.             }
  94.         }
  95.     }
  96.  
  97. if ( argc > 2 )
  98.     {
  99.     date_to_str(&date,&df,date_str);
  100.     printf("\n  File date: %s",date_str);
  101.     time_to_str(&time,&tf,time_str);
  102.     printf("\n  File time: %s",time_str);
  103.     }
  104.  
  105. if ( !date_valid(&date) )
  106.     {
  107.     printf("\nInvalid date.\n");
  108.     exit (-9);
  109.     }
  110.  
  111. if ( !time_valid(&time) )
  112.     {
  113.     printf("\nInvalid time.\n");
  114.     exit (-10);
  115.     }
  116.  
  117. result = set_file_date_time(normal_file_spec,NULL,&date,&time);
  118. if ( result > 0 )
  119.     printf("\n%d file%s modified.\n",
  120.         result, ( result>0 ? "s" : "" ) );
  121. else if ( !result )
  122.     printf("\nNo files modified.\n");
  123. else
  124.     printf("\nError %d",result);
  125.  
  126. exit(result);
  127. }
  128.